<?php
error_reporting( E_ALL | E_STRICT );
include('functions.php');

// Define the different number of documents to read in each run
$runs = array(
	'10',
);

// Call the function 'pickRandDoc()' to pick a random document ID.
// This is because MongoDB does not provide a "get random document" function
$rand = pickRandDoc();
$count = count($rand) - 1;

l("findOne");
$time = array();
set_time_limit(0);
ini_set("memory_limit","500M");

for($i=0; $i<5; $i++) {
	// Choose a random document ID
	$ran = $rand[mt_rand(0,$count)];
	$query = array('_id' => $ran);
	
	// Execute query with 'findOne'
	$start = timeit();
	$doc = q('post')->findOne($query);
	$end = timeit();
	$time[] = number_format($end - $start, 15);
}
l(avg($time));
unset($time);

l("\nfind + limit(1)");
$time = array();
set_time_limit(0);
ini_set("memory_limit","500M");

for($i=0; $i<5; $i++) {
	// Choose a random document ID
	$ran = $rand[mt_rand(0,$count)];
	$query = array('_id' => $ran);
	
	// Execute query with 'findOne'
	$start = timeit();
	$doc = q('post')->find($query)->limit(1);
	$end = timeit();
	$time[] = number_format($end - $start, 15);
}
l(avg($time));
unset($time);

echo "<h1>Done</h1>";
?>